import request from "@/utils/request";

// 更新用户信息
const updateUser = (data) => {
    return request({
        url: `/api/user/update`,
        method: 'post',
        data: data, // 注意要传入 data
        headers: { 'Content-Type': 'application/json;charset=utf-8' }
    });
};

// 根据用户 ID 获取用户信息
const getUserById = (id) => {
    return request({
        url: `/api/user/getById/${id}`, // 假设后端路径是 /api/user/{id}
        method: 'get'
    });
};

const getByName = (name) => {
    return request({
        url: `/api/user/getByName/${name}`, // 假设后端路径是 /api/user/{id}
        method: 'get'
    });
};

// 获取全部
const getAllUser = () =>{
    return request({
        url: "/api/user/getAllUser",
        method: "get"
    })
}

// 删除
const deleteUser = (userId) =>{
    return request({
        url: `/api/user/delete/${userId}`,
        method: "delete"
    })
}

const changeUserStatus = (userId,newStatus) =>{
    return request({
        url: `/api/user/delete/${userId}`,
        method: "post"
    })
}

const addUser = (User) =>{
    return request({
        url: `/api/user/add}`,
        method: "post",
        data:User
    })
}

export { updateUser, getUserById ,getByName,getAllUser,deleteUser,changeUserStatus,addUser};
